local BaseState = require("states.gen.base_state")

return Class{
   __includes = BaseState,
   init = function (self)
      BaseState.init(self)
   end,
   
   load = function (self)
      local ul = self.gui:ul(20, 20, 200, 450)
      ul.onclick = function (index, b)
	 if ul.selection == index then return end
	 ul.selection = index
	 local img = Game:load_map_image(ul.items[index].title)
	 self.view = love.graphics.newImage(img)
      end
      local ol = self.gui:ul(20, love.graphics.getHeight()-40, 200, 34, "Back")
      ol.onclick = function ()
	 Game:switch_state("mainmenu")
      end
      local pl = self.gui:ul(love.graphics.getWidth()-210, love.graphics.getHeight()-40, 200, 34, "Play")
      pl.onclick = function ()
	 if ul.selection then
	    Game:new_game(ul.items[ul.selection].title)
	 end
      end
      for _, filename in ipairs(_lf.getDirectoryItems("assets/maps")) do
	 ul:add(string.match(filename, "(%a+).map"))
      end
      ul:done()
      self.ul = ul
      self.ol = ol
      self.pl = pl
   end,
   
   show_info = function (self)
      
   end,
   
   draw = function (self)
      if self.view then
	 local x,y = self.gui:center(self.view:getDimensions())
	 love.graphics.draw(self.view, x, y)
      end
      self.gui:draw()
   end,

}
